package com.ruoyi.web.controller.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MoveLogHander implements InvocationHandler {
    Movable move;
    public MoveLogHander(Movable move)
    {
        this.move = move;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("method"+method.getName()+" start..");
        final Object invoke = method.invoke(move, args);
        System.out.println("method"+method.getName()+" end..");
        return invoke;
    }

    public static void main(String[] args) {
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles","true");
        final Movable o = (Movable) Proxy.newProxyInstance(MoveLogHander.class.getClassLoader(), new Class[]{Movable.class}, new MoveLogHander(new CarMove()));
        o.move();
        final Movable o1 = (Movable) Proxy.newProxyInstance(MoveLogHander.class.getClassLoader(), new Class[]{Movable.class}, new MoveLogHander(new PlanMove()));
        o1.move();
    }
}
